Skip to content

fix(id): roll back cancelled identity registrations - #9105

Merged
dezren39 merged 2 commits into
mainfrom
sweep/9089-id-registration-cancellation
Nov 14, 2026
Merged

dezren39 merged 2 commits into
mainfrom
sweep/9089-id-registration-cancellation

Conversation

@dezren39

@dezren39 dezren39 commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Fixes #9089.

Problem

The detached registration task could persist and account for a new identity after its request future was cancelled, before the caller created the name watcher and received the signed token. This left an unreachable identity consuming admission capacity, including after restart.

Solution

  • Move persistence, in-memory insertion, watcher creation, and token delivery into the detached task.
  • Require the caller to acknowledge receipt before the detached task commits the registration; if the caller is dropped first, remove the watcher, in-memory entry, and persistent row while holding the admission lock.
  • Retain in-memory accounting if persistent rollback itself fails, and log that failure.
  • Add a deterministic cancellation test that pauses after persistence/insertion, cancels the caller, and verifies both in-memory cleanup and an empty reopened database.

Verification


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 13, 2026 00:28
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 47 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1826bee5-9337-4410-b422-3d5d7edd0073
Commits

Reviewing files that changed from the base of the PR and between 662c010 and c5f3487.

Files selected for processing: 1

  • pkgs/id/crates/id-web/src/identity.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-14T19:48:58.938578Z
We couldn’t complete this review. Comment @codex review to try again.
c5f3487 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39

Copy link
Copy Markdown
Member Author

Verification update: the cancellation-aware registration/rollback implementation and deterministic persistent-store regression are in this PR. rustfmt --edition 2024 --check pkgs/id/src/web/identity.rs and git diff --check pass; independent review found no issues.

The focused cargo test --manifest-path pkgs/id/Cargo.toml --features web --lib test_cancelled_registration_rolls_back_persistent_state did not reach test execution. Compilation is blocked by the current web crate-split visibility/import errors tracked by #8795 (including private/missing id-worlds APIs); that issue's Drew-authored PR #8818 remains open and untouched. At this read, all PR basic checks were still pending. Leaving this PR open and unmerged until required CI and a runnable focused test are available.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3dd94b0cb1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +407 to +408
let _ = ack_tx.send(());
Ok(result)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Release the detached database handle before returning success

When a caller drops the store immediately after successful registration and reopens the same path, sending the acknowledgement only wakes the detached task; it does not wait for that task to release its captured Arc<IdentityDb>. The blocking pool can therefore attempt the reopen before the detached task resumes, causing redb to return DatabaseAlreadyOpen. This affects the existing test_restart_at_bound_serves_existing_refuses_new and can make test_wrong_key_refuses_to_open_store receive a locking error instead of the expected authentication error. Previously, awaiting the persistence task ensured its database reference was released before returning. Synchronize resource release on successful registration while preserving cancellation rollback.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c5f3487 (task 17181, lane code-b). register() now keeps the JoinHandle of the detached registration task and, after sending the acknowledgement, joins it before returning, so the clients write lock and the captured Arc are released before a successful return; a caller that drops the store and reopens the same path no longer races the detached task for the redb lock. Cancellation rollback is unchanged: dropping the caller before the acknowledgement still errors ack_rx and rolls back. Verification on the laptop: cargo test for id-web identity::tests, 43 passed and 0 failed, including test_cancelled_registration_rolls_back_persistent_state, test_restart_at_bound_serves_existing_refuses_new, and test_wrong_key_refuses_to_open_store; rustfmt --check clean. The branch was also rebased onto current main (the change now lands in pkgs/id/crates/id-web/src/identity.rs after the crate split).

@dezren39 dezren39 added work/assigned Queue worker lifecycle state queue/claimed Queue worker lifecycle state status/in-progress Queue worker lifecycle state labels Nov 14, 2026
@dezren39

Copy link
Copy Markdown
Member Author

agent-note:v1
state: picked-up
task: 17181
lane: code-b
worker: repo-worker-code
note: Shepherding PR #9105 in task 17181. Fresh revalidation: PR open, no hold labels (held/user-owned/do-not-merge/do-not-auto-edit absent), head matches packet. Found mergeable=false (dirty) against current main and one undispositioned Codex P2 finding (detached task can return success before releasing its database handle, racing a store reopen). Rebased the head branch onto current main in a laptop worktree (clean rebase; the change now lands in pkgs/id/crates/id-web/src/identity.rs after the crate split) and applied a fix for the Codex finding: register() now joins the detached registration task after the acknowledgement, so the clients write lock and database handle are released before it returns. Targeted id-web identity tests are running on the laptop; will push, reply on the Codex thread, and merge only on verified green.

@dezren39
dezren39 force-pushed the sweep/9089-id-registration-cancellation branch from 3dd94b0 to c5f3487 Compare November 14, 2026 19:48
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@dezren39
dezren39 merged commit fdbabb3 into main Nov 14, 2026
2 checks passed
@dezren39
dezren39 deleted the sweep/9089-id-registration-cancellation branch November 14, 2026 19:50
@dezren39 dezren39 removed status/in-progress Queue worker lifecycle state queue/claimed Queue worker lifecycle state work/assigned Queue worker lifecycle state labels Nov 14, 2026
@dezren39

Copy link
Copy Markdown
Member Author

agent-note:v1
state: done
task: 17181
lane: code-b
worker: repo-worker-code
note: PR #9105 merged in task 17181. Rebased onto current main, fixed the Codex P2 finding (register joins the detached registration task after acknowledgement so the database handle and write lock are released before return; reply posted on the Codex thread), targeted tests passed (id-web identity::tests 43 passed, 0 failed), merge commit fdbabb3. Issue #9089 closed by the merge. The mcpx-test failures on the pre-rebase head were in an unrelated package and did not block the merge under the standing merge criteria (targeted tests verified, diff matches intent, no hold labels).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(id): avoid orphaned identities when registration is cancelled

1 participant